<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script src="spellcheck_test.js"></script>

<script>
function pasteHTMLToDest(document, html)
{
  document.getSelection().setClipboardData(html);
  document.getElementById('dest').focus();
  document.execCommand('Paste');
}

spellcheck_test(
    '<div contenteditable id="dest">|</div>',
    document => pasteHTMLToDest(document, 'zz apple.'),
    '<div contenteditable id="dest">#zz# apple.</div>',
    'Paste plain text into editable <div>.');

spellcheck_test(
    '<div contenteditable id="dest">|</div>',
    document => pasteHTMLToDest(document,
                                'z<b>z appl</b>e.'),
    [
      '<div contenteditable id="dest">',
        '#z#<b>#z# appl</b>e.',
      '</div>'
    ].join(''),
    'Paste decorated text into editable <div>.');

spellcheck_test(
    '<div contenteditable id="dest">|</div>',
    document => pasteHTMLToDest(
        document, 'zz zz zz.'),
    [
      '<div contenteditable id="dest">',
        '#zz# #zz# #zz#.',
      '</div>'
    ].join(''),
    'Paste text with multiple errors into editable <div>.');

spellcheck_test(
    '<input id="dest" type="text">|',
    document => pasteHTMLToDest(document, 'zz apple.'),
    '<input id="dest" type="text" value="#zz# apple.">',
    'Paste plain text into <input>.');

spellcheck_test(
    '<input id="dest" type="text">|',
    document => pasteHTMLToDest(document,
                                'z<b>z appl</b>e.'),
    '<input id="dest" type="text" value="#zz# apple.">',
    'Paste decorated text into <input>.');

spellcheck_test(
    '<input id="dest" type="text">|',
    document => pasteHTMLToDest(
        document, 'zz zz zz.'),
    '<input id="dest" type="text" ' +
      'value="#zz# #zz# #zz#.">',
    'Paste text with multiple errors into <input>.');

spellcheck_test(
    '<textarea id="dest">|</textarea>',
    document => pasteHTMLToDest(document, 'zz apple.'),
    '<textarea id="dest">#zz# apple.</textarea>',
    'Paste plain text into <textarea>.');

spellcheck_test(
    '<textarea id="dest">|</textarea>',
    document => pasteHTMLToDest(document,
                                'z<b>z appl</b>e.'),
    '<textarea id="dest">#zz# apple.</textarea>',
    'Paste decorated text into <textarea>.');

spellcheck_test(
    '<textarea id="dest">|</textarea>',
    document => pasteHTMLToDest(
        document, 'zz zz zz.'),
    [
      '<textarea id="dest">',
        '#zz# #zz# #zz#.',
      '</textarea>'
    ].join(''),
    'Paste text with multiple errors into <textarea>.');
</script>
